package com.alex.common.tools;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.tools.view.CookieTool;

/**
 * MaxAge 单位 秒
 * 
 * @author alex
 * 
 */
public class CookieUtils extends CookieTool {

	public CookieUtils(HttpServletResponse response) {
		super();
		this.setResponse(response);
	}

	public CookieUtils(HttpServletRequest request) {
		super();
		this.setRequest(request);
	}

	public CookieUtils(HttpServletRequest request, HttpServletResponse response) {
		super();
		this.setRequest(request);
		this.setResponse(response);
	}

	@Deprecated
	public void remove(String name) {
		this.add(name, "", 0);
	}

	public void remove(Cookie cookie) {
		cookie.setMaxAge(0);
		response.addCookie(cookie);
	}
}
